#include <m68332.h>
#include <typedefs.h>
#include <p_status.h>
#include <status.h>
#include <error.h>
#include <zone_status.h>
#include <zone_config.h>
#include <zone_ui.h>
#include <display_ui.h>
#include <display.h>
#include <exception.h>
#include <messages.h>
#include <sig_types.h>
#include <diag.h>
#include <keyboard.h>
#include <config.h>
#include <mio.h>
#include <method.h>
#include <cmd_set.h>
#include <hostutil.h>
#include <wkfutil.h>
#include <p_ui.h>
INT8   ZONES_CONFIG2 = 0;       //in include/iomap.h
INT8   DISCRETE_IN1 = 0;        //in include/iomap.h
INT8   APG_BUS_IN = 0;          //in include/iomap.h
INT8   APG_BUS_OUT = 0;         //in include/iomap.h
INT8   DSP_BOOT = 0;            //in include/iomap.h
INT8 DETECTOR_IN = 0;           //in include/iomap.h
INT8 DISCRETE_IN2 = 0;          //in include/iomap.h
INT8 BCD_IN = 0;                //in include/iomap.h
INT8 KEYBOARD = 0;              //in include/iomap.h
INT8 ZONES_CONFIG1 = 0;         //in include/iomap.h
INT8 RESET_LATCH1 = 0;          //in include/iomap.h
INT8 ZONES_OUT1 = 0;            //in include/iomap.h
INT8 ZONES_OUT2 = 0;            //in include/iomap.h

U_INT16   Reading;              //in include/status.h
U_INT16   Reading_Noise;        //in include/status.h
//BIT8      DC_Use_Check_Area = 0;//in hostcmd/cmdproc.c
UPLD_WKFILE_TYPE Upld_wkfile[4];//in hostcmd/wkfutil.c
/*
U_INT16   Cmd_Port = 0;         //in hostcmd/hostutil.c
U_INT16  Host_Error_Count[5];   //in hostcmd/hostutil.c
INT16 StrLen(BIT8 *str)         //in hostcmd/hostutil.c
{
INT16 n;

   n = 0;
   while(*str++)
   {
      n++;
   }
   return  n;
}
INT16 StrNCmp(BIT8 *str1,BIT8 *str2,INT16 n) //in hostcmd/hostutil.c
{
   do{
      if(*str1 != *str2)
      {
         return 0;
      }
      str1++;
      str2++;
      n--;
   } while(n);
   return  1;
}
void StrNCpy(BIT8 *to_str,BIT8 *from_str,INT16 n)//in hostcmd/hostutil.c
{
   do
   {
      *to_str++ = *from_str++;
   } while(--n && *from_str);
   *to_str = 0x0;
   return;
}
void CmdErrorHandler(CMD_TYPE *p_cmd,U_INT16 param,UI_ERR error)//in hostcmd/hostutil.c
{
   printf("call CmdErrorHandler----error param:%d,error:%d\n",param,error);
}

U_INT16 PutAsciiParam(BIT8  *from_str, BIT8   *to_loc)//in hostcmd/hostutil.c
{
U_INT16   len;
U_INT16   i;

   len = StrLen(from_str);
   for ( i = 0; i < len ; i++ )
   {
      *to_loc++ = *from_str++;
   }
   return  len;
}
*/


DIAG_STATE Diag_State;          //in diag/diag.c

UI_ERR LoadSequence (U_INT8 seq)//in sequence/seq_store.c
{   
  printf("call LoadSequence\n");
  return( OK );
}
UI_ERR SequenceExists (U_INT8 seq)//in sequence/seq_store.c
{   
  printf("call SequenceExists\n");
  return( OK );
}
UI_ERR SetDiagMode( ON_OFF on_off )//in diag/diag.c
{   
  printf("call SetDiagMode\n");
  return( OK );
}
U_INT8    Refresh_Count = 0;    //in keyboard/kbdtask.c
STATE     Active_State;         //in keyboard/kbdtask.c
BIT8      Pneu_Keys_Enabled = 0;//in keyboard/kbdtask.c
U_INT8    Digits = 0;           //in keyboard/kbdtask.c
BIT8      Number_Image[20];     //in keyboard/kbdtask.c
BIT8      Info_Displayed = 0;   //in keyboard/kbdtask.c
void EnterClockTableTime(void)  //in keyboard/r_clktbl.c
{
  printf("call Number_Tble->EnterClockTableTime\n");
}

static const NUMBER_TBL Clock_Time_Tbl = {5, 0, EnterClockTableTime};// in keyboard/r_clktbl.c
pNUMBER_TBL Number_Tbl = &Clock_Time_Tbl ;//in keyboard/kbdtask.c

void InitializeKeyboard(void) //in keyboard/kbdtask.c
{
   Active_State.State    = S_DEFAULT;
   Active_State.HelpFn   = NULL;
   Active_State.ScrollFn = NULL;
   Active_State.Setpt_Tbl = NULL;
   Active_State.Refresh_On  = FALSE;
}
void DisableWatchMode(void) //in keyboard/kbdtask.c
{
  printf("call DisableWatchMode\n");
}
BIT8 GetWarningBeepEnabled (void) //in keyboard/kbd_ui.c
{
   return WarningBeepEnabled;
}
U_INT16 GetDetGas1Msg( POSITION position, U_INT16 msg_type ) //in keyboard/kbd_util.c
{
  printf("call GetDetGas1Msg\n");
  return NO_MSG;
}
U_INT16 GetDetGas2Msg( POSITION position, U_INT16 msg_type ) //in keyboard/kbd_util.c
{
  printf("call GetDetGas2Msg\n");
  return NO_MSG;
}
U_INT16 GetDetGas3Msg( POSITION position, U_INT16 msg_type ) //in keyboard/kbd_util.c
{
  printf("call GetDetGas3Msg\n");
  return NO_MSG;
}
U_INT32 GetSccSignalTypeMsg( pCCOMP_TABLE pccomp ) //in keyboard/kbd_util.c
{
  printf("call GetSccSignalTypeMsg\n");
  return MSG_DET_NONE;
}
U_INT16 GetSignalTypeMsg( pSIG_TABLE psignal ) //in keyboard/kbd_util.c
{
  printf("call GetSignalTypeMsg\n");
  return SIGNAL_DIAGNOSTIC_MSG;
}
void ForceKeyboardDisplayRefresh (void) //in keyboard/kbd_util.c
{
  printf("call ForceKeyboardDisplayRefresh\n");
}


unsigned int __tableU(void *array, short x, unsigned int size) //unkown //include/m68332.h
{
//  printf("call __tableU size=%d U_INT16=%d\n",size,sizeof(U_INT16));
  if(size == sizeof(U_INT8))
    return ((U_INT8*)array)[x];
  else if(size == sizeof(U_INT16))
    return ((U_INT16*)array)[x>>8];
  else if(size == sizeof(U_INT32))
    return ((U_INT32*)array)[x];
}
int __tableS(void *array, short x, unsigned int size)   //unkown //include/m68332.h
{
  printf("call __tableS\n");
  if(size == sizeof(INT8))
    return ((INT8*)array)[x];
  else if(size == sizeof(INT16))
    return ((INT16*)array)[x];
  else if(size == sizeof(INT32))
    return ((INT32*)array)[x];
}
unsigned int interpolateU(unsigned int y1, unsigned int y2, char x) //include/m68332.h
{
  unsigned int y;
  unsigned char m = (unsigned char)x;
  if(m > 254)
    y = y2;
  else
    y = (y1 + y2*m)/(1+m);
  printf("call interpolateU\n");
  return y;
}
void InitPneuKeys( void ) //in flow/pneu_keys.c
{
  printf("call InitPneuKeys\n");
}
void PneuFakeDisplay( void ) //in flow/pneu_keys.c
{
  printf("call PneuFakeDisplay\n");
}
BIT8 SequenceInProgress (void)//in sequence/seq_ui.c
{
  printf("call SequenceInProgress\n");
 return 0;
}
BIT8 GsvInjInProgress (void)//in sequence/seq_ui.c
{
  printf("call GsvInjInProgress\n");
 return 0;
}
void SetSampleNumbers (void)//in sequence/seq_ui.c
{
  printf("call SetSampleNumbers\n");
}
void DefaultGsvInletIfHwChanged (U_INT8 valve)//in valve/valve_init.c
{
  printf("call DefaultGsvInletIfHwChanged\n");
}
void CheckValveConfig (void)//in valve/valve_init.c
{
  printf("call CheckValveConfig\n");
}
void SwitchValveImage (ON_OFF state, U_INT8 valve)//in valve/valve_ctrl.c
{
  printf("call SwitchValveImage\n");
}
void ServiceGsvAndMultiValve (void)//in valve/valve.c
{
//  printf("call ServiceGsvAndMultiValve\n");
}
VALVE_TYPE GetValveType( U_INT8 valve )//in valve/valve_ui.c
{
  printf("call GetValveType\n");
  return NO_VALVE;
}
INT32 GetValveLoopVolume( U_INT8 valve )//in valve/valve_ui.c
{
  printf("call GetValveLoopVolume\n");
  return 0;
}
VALVE_POSITION  GetValveInlet( U_INT8 valve )//in valve/valve_ui.c
{
  printf("call GetValveInlet\n");
  return NO_CONNECTION;
}
INT32 GetMultiTime (void)//in valve/valve_ui.c
{
  printf("call GetMultiTime\n");
  return 0;
}
ON_OFF GetInvertBcd (void)//in valve/valve_ui.c
{
  printf("call GetInvertBcd\n");
  return 0;
}
void TakeThisValveConfigAndShoveIt (void)//in valve/valve_init.c
{
  printf("call TakeThisValveConfigAndShoveIt\n");
}
void ExecuteRunTimeTable ( void )//in timetable/run_table.c
{
  printf("call ExecuteRunTimeTable\n");
}
void UndoRunTableChanges ( void )//in timetable/run_table.c
{
  ResetAuxPressures();
  ResetSigPathState();
  RTTResetDetectorStates();
  printf("call UndoRunTableChanges\n");
}
INT16 NumRunTableEntries( void )//in timetable/run_table.c
{
  printf("call NumRunTableEntries\n");
  return 0;
}
pINLET_STATUS PositionToInlet( POSITION position )//in diag/pneu_diag.c
{
   if ( position == FRONT ) return pFRONT_INLET;

   return pBACK_INLET;
}

UI_ERR SetDiagPneuDutyCycle( U_INT8 channel, INT32 duty_cycle )//in diag/pneu_diag.c
{
   UI_ERR return_code;

   return_code = SetDiagMode( ON );

   if ( return_code != OK )
   {
      return( return_code );
   }

   return SetDutyCycleSetpt( channel, duty_cycle );
}
UI_ERR SetSplitValveManualControl( pINLET_STATUS status, ON_OFF on_off )//in diag/pneu_diag.c
{
   UI_ERR error;

   if ( on_off == ON )
   {
      error = SetDiagMode( ON );

      if ( error != OK )
      {
         return error;
      }
   }

   SetInletDiagMode( status, (BIT8)on_off );
   return OK;
}
